package com.hanlink.dsp.ui.widget;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;

import com.qztech.sdk.R;

/**
 * @author Zhanghb
 * Email: 2573475062@qq.com
 * Date : 2019-12-28 22:42
 */
public class BassPopWindow extends PopupWindow {

    private ListView mListView;
    private int position;

    public BassPopWindow(Context context, CharSequence[] array, int width, int position) {
        super(context);
        setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        setWidth(width);
        setOutsideTouchable(true);
        setFocusable(true);
        this.position = position;
        setBackgroundDrawable(context.getResources().getDrawable(com.hanlink.res.R.drawable.border_common));
        View contentView = LayoutInflater.from(context).inflate(R.layout.bass_pop_window, null, false);
        setContentView(contentView);
        mListView = contentView.findViewById(R.id.list);
        ArrayAdapter<CharSequence> arrayAdapter = new ArrayAdapter<>(context, R.layout.pop_list_item, array);
        mListView.setAdapter(arrayAdapter);
        mListView.setOnItemClickListener((parent, view, index, id) -> {
            this.position = index;
            this.dismiss();
        });
    }

    public int getPosition() {
        return position;
    }
}
